﻿using System;
using System.Runtime.InteropServices;
using System.Collections.Generic;
using System.Text;

namespace PickGold.Api
{
	public static class Gdi32
	{
		public const string DLL = Common.DLL_GDI32;

		public const int SRCCOPY_BITBLT_DWROP = 0x00CC0020;

		/// <summary>
		/// BitBlt
		/// </summary>
		/// <param name="hdcDest">目标 DC的句柄 </param>
		/// <param name="nXDest"></param>
		/// <param name="nYDest"></param>
		/// <param name="nWidth"></param>
		/// <param name="nHeight"></param>
		/// <param name="hdcSrc">源DC的句柄 </param>
		/// <param name="nXSrc"></param>
		/// <param name="nYSrc"></param>
		/// <param name="dwRop">光栅的处理数值 </param>
		/// <returns></returns>
		[DllImport(DLL)]
		public static extern bool BitBlt(IntPtr hdcDest, int nXDest, int nYDest, int nWidth, int nHeight, IntPtr hdcSrc, int nXSrc, int nYSrc, int dwRop);

		[DllImport(DLL)]
		public static extern IntPtr CreateCompatibleBitmap(IntPtr hDC, int nWidth, int nHeight);

		[DllImport(DLL)]
		public static extern IntPtr CreateCompatibleDC(IntPtr hDC);

		[DllImport(DLL)]
		public static extern bool DeleteDC(IntPtr hDC);

		[DllImport(DLL)]
		public static extern bool DeleteObject(IntPtr hObject);

		[DllImport(DLL)]
		public static extern IntPtr SelectObject(IntPtr hDC, IntPtr hObject);

		/// <summary>
		/// 按照规定的格式创建一幅与设备有关位图
		/// </summary>
		/// <param name="nWidth">位图宽度，以像素为单位</param>
		/// <param name="nHeight">位图高度，以像素为单位</param>
		/// <param name="nPlanes">色层数量</param>
		/// <param name="nBitCount">每像素的位数</param>
		/// <param name="lpBits">指向欲载入位图的数据的指针。可设为零，表示不对位图进行初始化。这个数据的格式必须与设备的要求相符。扫描线必须对齐16位字边界</param>
		/// <returns>执行成功返回位图的句柄，零表示失败</returns>
		[DllImport(DLL)]
		public static extern IntPtr CreateBitmap(int nWidth, int nHeight, int nPlanes, int nBitCount, object lpBits);
		/// <summary>
		/// 按照规定的格式创建一幅与设备有关位图
		/// </summary>
		/// <param name="nWidth">位图宽度，以像素为单位</param>
		/// <param name="nHeight">位图高度，以像素为单位</param>
		/// <param name="nPlanes">色层数量</param>
		/// <param name="nBitCount">每像素的位数</param>
		/// <param name="lpBits">指向欲载入位图的数据的指针。可设为零，表示不对位图进行初始化。这个数据的格式必须与设备的要求相符。扫描线必须对齐16位字边界</param>
		/// <returns>执行成功返回位图的句柄，零表示失败</returns>
		[DllImport(DLL)]
		public static extern IntPtr CreateBitmap(int nWidth, int nHeight, int nPlanes, int nBitCount, IntPtr lpBits);
		/// <summary>
		/// 按照规定的格式创建一幅与设备有关位图
		/// </summary>
		/// <param name="nWidth">位图宽度，以像素为单位</param>
		/// <param name="nHeight">位图高度，以像素为单位</param>
		/// <param name="nPlanes">色层数量</param>
		/// <param name="nBitCount">每像素的位数</param>
		/// <param name="lpBits">指向欲载入位图的数据的指针。可设为零，表示不对位图进行初始化。这个数据的格式必须与设备的要求相符。扫描线必须对齐16位字边界</param>
		/// <returns>执行成功返回位图的句柄，零表示失败</returns>
		[DllImport(DLL)]
		public static extern IntPtr CreateBitmap(int nWidth, int nHeight, int nPlanes, int nBitCount, int lpBits);

		/// <summary>
		/// 将来自一幅位图的二进制位复制到一幅与设备无关的位图里
		/// 起始扫描线与起点有关。除非将BITMAPINFOHEADER结构的biHeight字段设为负值，否则起点就位于左下角 
		/// </summary>
		/// <param name="aHDC">定义了与设备有关位图hBitmap的配置信息的一个设备场景的句柄</param>
		/// <param name="hBitmap">源位图的句柄。绝对不能将这幅位图选入设备场景</param>
		/// <param name="nStartScan">欲复制到DIB中的第一条扫描线的编号</param>
		/// <param name="nNumScans">欲复制的扫描线数量</param>
		/// <param name="lpBits">指向一个缓冲区的指针。这个缓冲区将用于装载采用DIB格式的信息，但不取回数据</param>
		/// <param name="lpBI">BITMAPINFO，对lpBits DIB的格式及颜色进行说明的一个结构。在BITMAPINFOHEADER结构中，从biSize到biCompression之间的所有字段都必须初始化</param>
		/// <param name="wUsage">DIB_PAL_COLORS、DIB_RGB_COLORS、常数之一</param>
		/// <returns>非零表示成功，零表示失败。在Windows 95中，返回值是返回的扫描线数量</returns>
		[DllImport(DLL)]
		public static extern bool GetDIBits(IntPtr aHDC, IntPtr hBitmap, int nStartScan, int nNumScans, object lpBits, BITMAPINFO lpBI, int wUsage);

		/// <summary>
		/// 设置字间距
		/// </summary>
		/// <param name="hdc">目标句柄</param>
		/// <param name="nCharExtra">字间距</param>
		/// <returns></returns>
		[DllImport(DLL)]
		public static extern int SetTextCharacterExtra(IntPtr hdc, int nCharExtra);

		[DllImport(DLL)]
		public static extern int GetDeviceCaps(IntPtr hdc, int index);

		//[DllImport(DLL)]
		//public static extern int GdipMeasureDriverString(IntPtr graphics, string text, int length, IntPtr font, PointF[] positions, int flags, IntPtr matrix, ref RectangleF bounds);


		/// <summary>
		/// 添加字体
		/// </summary>
		/// <param name="lpFileName">字体文件名</param>
		/// <returns>？</returns>
		[DllImport(DLL)]
		public static extern int AddFontResource(string lpFileName);

		/// <summary>
		/// 移除字体
		/// </summary>
		/// <param name="lpFileName">字体文件名</param>
		/// <returns>？</returns>
		[DllImport(DLL)]
		public static extern int RemoveFontResource(string lpFileName);

		[DllImport(DLL)]
		public static extern IntPtr BeginPath(IntPtr hdc);
		[DllImport(DLL)]
		public static extern int SetBkMode(IntPtr hdc, int nBkMode);
		[DllImport(DLL)]
		public static extern IntPtr EndPath(IntPtr hdc);
		[DllImport(DLL)]
		public static extern IntPtr PathToRegion(IntPtr hdc);
		[DllImport(DLL)]
		public static extern int Ellipse(IntPtr hdc, int x1, int y1, int x2, int y2);

		[DllImport(DLL)]
		public static extern int Circle(int x, int y, int r);

		[DllImport(DLL)]
		public static extern IntPtr CreateRoundRectRgn(int x1, int y1, int x2, int y2, int cx, int cy);
	}
}
